package com.zz.ad.utils;

import java.util.Map;
import java.util.function.Supplier;

/**
 * Author: zz
 * Date: 2020/2/17
 * Description: 当Map中的key不存在的时候，帮这个key去new一个新的value出来
 */
public class CommonUtils {

    public static <K, V> V getorCreate(K key, Map<K, V> map, Supplier<V> factory) {
        return map.computeIfAbsent(key, k -> factory.get());
    }
}
